package org.foj.model;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.appfuse.model.BaseObject;

import javax.persistence.*;
import javax.persistence.Entity;
import java.io.Serializable;
import java.util.Date;

import org.codehaus.xfire.aegis.type.java5.XmlElement;

/**
 * @author jeremy anderson
 */
@Entity
public class Issue extends BaseObject implements Serializable {

  private Long id;
  private String project;
  private String description;
  private String type;
  private String severity;
  private String status;
  private String details;
  private String reportedBy;
  private Date reportedOn;
  private String assignedTo;
  private Double estimatedHours;

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }

  public String getProject() {
    return project;
  }

  public void setProject(String project) {
    this.project = project;
  }

  public String getDescription() {
    return description;
  }

  public void setDescription(String description) {
    this.description = description;
  }

  public String getType() {
    return type;
  }

  public void setType(String type) {
    this.type = type;
  }

  public String getSeverity() {
    return severity;
  }

  public void setSeverity(String severity) {
    this.severity = severity;
  }

  public String getStatus() {
    return status;
  }

  public void setStatus(String status) {
    this.status = status;
  }

  public String getDetails() {
    return details;
  }

  public void setDetails(String details) {
    this.details = details;
  }

  public String getReportedBy() {
    return reportedBy;
  }

  public void setReportedBy(String reportedBy) {
    this.reportedBy = reportedBy;
  }

  @XmlElement(minOccurs = "0", nillable = true)
  public Date getReportedOn() {
    return reportedOn;
  }

  public void setReportedOn(Date reportedOn) {
    this.reportedOn = reportedOn;
  }

  public String getAssignedTo() {
    return assignedTo;
  }

  public void setAssignedTo(String assignedTo) {
    this.assignedTo = assignedTo;
  }

  public Double getEstimatedHours() {
    return estimatedHours;
  }

  public void setEstimatedHours(Double estimatedHours) {
    this.estimatedHours = estimatedHours;
  }

  @Override
  public int hashCode() {
    return new HashCodeBuilder(11, 37).append(id).toHashCode();
  }

  @Override
  public boolean equals(Object o) {
    if (null == o) return false;
    if (!(o instanceof Issue)) return false;
    if (this == o) return true;

    Issue input = (Issue) o;
    return new EqualsBuilder()
        .append(this.getId(), input.getId())
        .isEquals();

  }

  @Override
  public String toString() {
    return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
        .append(id)
        .append(project)
        .append(description)
        .toString();
  }
}
